﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using TfsMerge.BO;
using DevExpress.XtraTreeList.Nodes;

namespace TfsMerge.View
{
    public partial class SelectBranchView : BaseDialog
    {
        public string Branch { get; private set; }

        public SelectBranchView(IEnumerable<UIBranchObject> branches)
        {
            InitializeComponent();

            treeList.DataSource = branches
                .ToList();

            treeList.MouseDoubleClick += TreeListMouseDoubleClick;
        }

        protected override void OnShown(EventArgs e)
        {
            foreach (TreeListNode node in treeList.Nodes)
                node.Expanded = true;

            base.OnShown(e);
        }

        void TreeListMouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (treeList.FocusedNode == null)
                return;

            OnOkClick();
        }

        public override void OnOkClick()
        {
            Branch = treeList.FocusedNode.GetDisplayText(0);
            base.OnOkClick();
        }
    }
}
